package com.example.springboot.controller;


import com.example.springboot.base.Result;
import com.example.springboot.service.UserInfoService;
import com.github.qcloudsms.httpclient.HTTPException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 赵久燚
 * @since 2022-07-11 19:45:42
 */
@RestController
@Api(tags = "用户")
@RequestMapping("/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(
            @RequestParam("username") String username,
            @RequestParam("password") String password
    ){
        return userInfoService.userLogin(username,password);
    }
    @ApiOperation("注册")
    @PostMapping("/register")
    public Result register(
            @RequestParam("userName") String userName,
            @RequestParam("password") String password,
            @RequestParam("phoneNumber") String phoneNumber,
            @RequestParam("verCode") String verCode
    ){
        return userInfoService.userRegister(userName,password,phoneNumber,verCode);
    }


    @ApiOperation("发送验证码")
    @PostMapping("/verCode")
    public Result varCode(
            @RequestParam("phoneNumber") String phoneNumber
    ) throws HTTPException, IOException {
        return userInfoService.sendVerCode(phoneNumber);
    }
    @ApiOperation("token测试")
    @PostMapping("/token")
    public Result token(
            HttpServletRequest request
    ){
        String token = request.getHeader("token");
        return userInfoService.token(token);
    }
}

